package cn.bfay.lion.rest.manager.impl;

import cn.bfay.lion.rest.client.JingdongClient;
import cn.bfay.lion.rest.client.req.AddProductReq;
import cn.bfay.lion.rest.client.rsp.GeneralPromotionLinkRsp;
import cn.bfay.lion.rest.client.rsp.ProductDetailInfoRsp;
import cn.bfay.lion.rest.client.rsp.ProductInfoRsp;
import cn.bfay.lion.rest.manager.JingdongManager;
import cn.bfay.web.result.PageResult;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * JingdongManagerImpl.
 *
 * @author wangjiannan
 */
@RequiredArgsConstructor
@Component
public class JingdongManagerImpl implements JingdongManager {
    @Lazy
    private final JingdongClient jingdongClient;

    @Override
    public void addProductBySkuid(String skuid) {
        jingdongClient.addProductBySkuid(AddProductReq.builder().skuid(skuid).build());
    }

    @Override
    public ProductInfoRsp getProductInfoBySkuid(String skuid) {
        return jingdongClient.getProductInfoBySkuid(skuid);
    }

    @Override
    public PageResult<ProductInfoRsp> getProductInfoByPaging(String name, Long pageNum, Long pageSize) {
        return jingdongClient.getProductInfoByPaging(name, pageNum, pageSize);
    }

    @Override
    public List<ProductDetailInfoRsp> getProductDetailInfos(String skuid) {
        return jingdongClient.getProductDetailInfos(skuid);
    }

    @Override
    public List<ProductInfoRsp> getProductInfoBySkuids(String skuids) {
        return jingdongClient.getProductInfoBySkuids(skuids);
    }

    @Override
    public String getPromotionCommon(String skuid) {
        GeneralPromotionLinkRsp generalPromotionLinkRsp = jingdongClient.getPromotionCommon(skuid);
        return generalPromotionLinkRsp.getClickUrl();
    }
}
